package com.xtgg.baby;

import com.xtgg.R;
import com.xtgg.manager.BaseActivity;

import android.os.Bundle;
import android.app.Dialog;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;

public class DeviceAddActivity extends BaseActivity implements
		OnClickListener {

	BluetoothAdapter mAdapter = BluetoothAdapter.getDefaultAdapter();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_device_add);

		findViewById(R.id.add_device).setOnClickListener(this);
		findViewById(R.id.left).setOnClickListener(this);
	}

	@Override
	public void onClick(View arg0) {
		switch (arg0.getId()) {
		case R.id.add_device:
			checkBule();
			break;
			
		case R.id.left:
			finish();
			break;
		}
	}
	
	void checkBule() {
		if (!mAdapter.isEnabled()) {
			showQuery();
		} else {
			startActivity(new Intent(this,DeviceSearchActivity.class));
			finish();
		}
	}
	
	void showQuery() {
		final Dialog dialog = new Dialog(this, R.style.dialog);
		dialog.setContentView(R.layout.dialog_sheet);
		dialog.findViewById(R.id.confirm).setOnClickListener(
				new OnClickListener() {
					@Override
					public void onClick(View arg0) {
						mAdapter.enable();
						startActivity(new Intent(DeviceAddActivity.this,DeviceSearchActivity.class));
						dialog.dismiss();
						finish();
					}
				});
		dialog.findViewById(R.id.forbide).setOnClickListener(
				new OnClickListener() {
					@Override
					public void onClick(View arg0) {
						dialog.dismiss();
					}
				});
		dialog.show();
	}
}